using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;
using SCS.Common.Models;
namespace SCS.DAL.Mapping
{
    public class PrivateMessageMap : EntityTypeConfiguration<PrivateMessage>
    {
        public PrivateMessageMap()
        {
            // Primary Key
            this.HasKey(t => t.messageID);

            // Properties
            this.Property(t => t.messageID)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            this.Property(t => t.subject)
                .IsRequired()
                .HasMaxLength(80);

            this.Property(t => t.message)
                .IsRequired();

            // Table & Column Mappings
            this.ToTable("PrivateMessage");
            this.Property(t => t.messageID).HasColumnName("messageID");
            this.Property(t => t.userToID).HasColumnName("userToID");
            this.Property(t => t.userFromID).HasColumnName("userFromID");
            this.Property(t => t.dateSent).HasColumnName("dateSent");
            this.Property(t => t.subject).HasColumnName("subject");
            this.Property(t => t.message).HasColumnName("message");
            this.Property(t => t.isRead).HasColumnName("isRead");
            this.Property(t => t.isReceiverDeleted).HasColumnName("isReceiverDeleted");
            this.Property(t => t.isSenderDeleted).HasColumnName("isSenderDeleted");

            // Relationships
            this.HasRequired(t => t.UserTo)
                .WithMany(t => t.PrivateMessages)
                .HasForeignKey(d => d.userToID);
            this.HasRequired(t => t.UserFrom)
                .WithMany(t => t.PrivateMessages1)
                .HasForeignKey(d => d.userFromID);

        }
    }
}
